/**************************************************************************************
*
*	Copyright (C) 2009 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	RenderView.cpp
*
*	Comments	-	See RenderView.h
*
**************************************************************************************/
#include "../Include/RenderView.h"

namespace Pulse
{
	RenderView::RenderView( ComponentCamera *pCamera )
		: m_pCamera( pCamera )
	{
	}

	RenderView::~RenderView( void )
	{

	}

	void RenderView::AddRenderEntry( RenderEntry *pEntry )
	{
		ERenderViewStage::Type stage = pEntry->GetStage();
		ERenderViewStageStep::Type stageStep = pEntry->GetStageStep();

		m_renderStages[stage].m_renderteps[stageStep].PushBack( pEntry );
	}

	void RenderView::ExecuteRenderStages( GraphicsPipeline *pPipeline )
	{
		RenderEntry *pEntry;
		RenderStage *pRenderStage;
		RenderEntryList *pRenderList;

		for ( SIZE_T i = 0; i < ERenderViewStage::EnumCount; ++i )
		{
			pRenderStage = &m_renderStages[i];

			for ( SIZE_T j = 0; j <3; ++j )
			{
				pRenderList = &pRenderStage->m_renderteps[j];
				const SIZE_T numEntries = pRenderList->GetSize();

				for ( SIZE_T k = 0; k < numEntries; ++k )
				{
					//pEntry = pRenderList->TopAndPop();
					pEntry = pRenderList->operator[]( k );

					pEntry->PreExecute( pPipeline );
					pEntry->Execute( pPipeline );
					pEntry->PostExecute( pPipeline );
				}

				pRenderList->FastClear();
			}
		}

		// Since we are using stack to store render entries, they are automatically popped out.
	}

}